package com.ruoyi.carbon.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.DateUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.carbon.domain.ScmPurchasePlan;
import com.ruoyi.carbon.service.IScmPurchasePlanService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采购计划Controller
 * 
 * @author ruoyi
 * @date 2024-11-22
 */
@RestController
@RequestMapping("/carbon/scmPurchasePlan")
public class ScmPurchasePlanController extends BaseController
{
    @Autowired
    private IScmPurchasePlanService scmPurchasePlanService;

    /**
     * 查询采购计划列表
     */
    @PreAuthorize("@ss.hasPermi('carbon:scmPurchasePlan:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScmPurchasePlan scmPurchasePlan)
    {
        startPage();
        List<ScmPurchasePlan> list = scmPurchasePlanService.selectScmPurchasePlanList(scmPurchasePlan);
        return getDataTable(list);
    }

    /**
     * 导出采购计划列表
     */
    @PreAuthorize("@ss.hasPermi('carbon:scmPurchasePlan:export')")
    @Log(title = "采购计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScmPurchasePlan scmPurchasePlan)
    {
        List<ScmPurchasePlan> list = scmPurchasePlanService.selectScmPurchasePlanList(scmPurchasePlan);
        ExcelUtil<ScmPurchasePlan> util = new ExcelUtil<ScmPurchasePlan>(ScmPurchasePlan.class);
        util.exportExcel(response, list, "采购计划数据");
    }

    /**
     * 获取采购计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('carbon:scmPurchasePlan:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(scmPurchasePlanService.selectScmPurchasePlanById(id));
    }

    /**
     * 新增采购计划
     */
    @PreAuthorize("@ss.hasPermi('carbon:scmPurchasePlan:add')")
    @Log(title = "采购计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScmPurchasePlan scmPurchasePlan)
    {
        return toAjax(scmPurchasePlanService.insertScmPurchasePlan(scmPurchasePlan));
    }

    /**
     * 修改采购计划
     */
    @PreAuthorize("@ss.hasPermi('carbon:scmPurchasePlan:edit')")
    @Log(title = "采购计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScmPurchasePlan scmPurchasePlan)
    {
        scmPurchasePlan.setAuditTime(DateUtils.getNowDate());
        scmPurchasePlan.setAuditUser(getUsername());
        return toAjax(scmPurchasePlanService.updateScmPurchasePlan(scmPurchasePlan));
    }

    /**
     * 删除采购计划
     */
    @PreAuthorize("@ss.hasPermi('carbon:scmPurchasePlan:remove')")
    @Log(title = "采购计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(scmPurchasePlanService.deleteScmPurchasePlanByIds(ids));
    }
}
